In [ ]:
import pandas as pd
Useful information about the dataset used in this assignment can be found here.
Load up the mushroom dataset into dataframe X and verify you did it properly, and that you have not included any features that clearly shouldn't be part of the dataset.
You should not have any doubled indices. You can check out information about the headers present in the dataset using the link we provided above. Also make sure you've properly captured any NA values.
In [ ]:
# .. your code here ..
In [ ]:
# An easy way to show which rows have nans in them:
X[pd.isnull(X).any(axis=1)]
For this simple assignment, just drop any row with a nan in it, and then print out your dataset's shape:
In [ ]:
# .. your code here ..
Copy the labels out of the dataframe into variable y, then remove them from X.
Encode the labels, using the .map() trick we presented you in Module 5, using canadian:0, kama:1, and rosa:2.
In [ ]:
# .. your code here ..
Encode the entire dataframe using dummies:
Split your data into test and train sets. Your test size should be 30% with random_state 7.
Please use variable names: X_train, X_test, y_train, and y_test:
In [ ]:
# .. your code here ..
Create an DT classifier. No need to set any parameters:
In [ ]:
# .. your code here ..
Train the classifier on the training data and labels; then, score the classifier on the testing data and labels:
In [ ]:
# .. your code here ..
In [ ]:
print("High-Dimensionality Score: ", round((score*100), 3))
Use the code on the course's SciKit-Learn page to output a .DOT file, then render the .DOT to .PNGs.
You will need graphviz installed to do this. On macOS, you can brew install graphviz. On Windows 10, graphviz installs via a .msi installer that you can download from the graphviz website. Also, a graph editor, gvedit.exe can be used to view the tree directly from the exported tree.dot file without having to issue a call. On other systems, use analogous commands.
If you encounter issues installing graphviz or don't have the rights to, you can always visualize your .dot file on the website: http://webgraphviz.com/.
In [ ]: